const Base = require("./base.js");

module.exports = class extends Base {
  async visitAction() {
    const visitcount = await this.model("proxy")
      .where({ id: this.post("proxyid") })
      .increment("visit_total", 1);
    return this.success(visitcount);
  }
  async qrcodeAction() {
    const scene = `${this.post("goods_id")},${this.getLoginUserId()}`
    const path = 'pages/product/product'
    const sharelist = await this.model('user_sharelist').where({ user_id: this.getLoginUserId(), share_goods_id: this.post('goods_id') }).getField('share_qrcode', true)
    let result = sharelist
    if (!sharelist) {
      const hash = await this.service("weixin", "api").getqrcode(
        scene,
        "user" + this.getTime(),
        path
      );
      const qrcodeurl = `https://152.32.134.24/${hash.key}`;
      await this.model("user_sharelist")
        .add({
          user_id: this.getLoginUserId(),
          share_goods_id: this.post("goods_id"),
          share_count: 1,
          share_qrcode: qrcodeurl
        });
      result = qrcodeurl
    }else{
      await this.model('user_sharelist').where({ user_id: this.getLoginUserId(), share_goods_id: this.post('goods_id') }).increment('share_count',1)
    }
    return this.success(result);
  }
}

